<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>定时器动画</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      #test {
        width: 200px;
        height: 200px;
        background: green;
        position: absolute;
        left: 0;
        right: 0;
        top: 20px;
      }
    </style>
  </head>
  <body>
    <div id="test"></div>
    <!--定时器动画-->
    <script type="text/javascript">
      let i = 0;
      setInterval(function () {
        i++;
        document.getElementById("test").style.transform = `translateX(${i}px)`;
      }, 16);
    </script>
  </body>
</html>
